<template>
	<div class="GeneralROrderListing">
		<!-- <div class="page-top" v-if="this.$store.state.options.user.oda.notice != null">
			<dl class="notice">
				<dt><img src="../../../static/images/notice-red-mini.png" /></dt>
				<dd @click="$router.push('/public/message-detail?id=' + $store.state.options.user.oda.notice.id)">{{ $store.state.options.user.oda.notice.title }}
				</dd>
			</dl>
		</div> -->
		<van-tabs v-model="tabs.index" color="#00CC00" class="order-list-items">
			<van-tab title="待收取">
				<van-list v-model="collectGR.loading" :finished="collectGR.finished" finished-text="没有更多了" @load="onLoad(collectGR.textType)">
					<normal-order-list v-for="(item, index) in collectGR.dataset" :key="index" :ibase="item.base" :dataset="item.items" :textType="collectGR.textType" class="el-item" />
				</van-list>
			</van-tab>
			<van-tab title="待确认">
				<van-list v-model="confirmGR.loading" :finished="confirmGR.finished" finished-text="没有更多了" @load="onLoad(confirmGR.textType)">
					<normal-order-list v-for="(item, index) in confirmGR.dataset" :key="index" :ibase="item.base" :dataset="item.items" :textType="confirmGR.textType" class="el-item" />
				</van-list>
			</van-tab>
			<van-tab title="已完成">
				<van-list v-model="completeGR.loading" :finished="completeGR.finished" finished-text="没有更多了" @load="onLoad(completeGR.textType)">
					<normal-order-list v-for="(item, index) in completeGR.dataset" :key="index" :ibase="item.base" :dataset="item.items" :textType="completeGR.textType" class="el-item" />
				</van-list>
			</van-tab>
		</van-tabs>
		<tab-group :dataset="navButtonGroup" identity="4" index=0></tab-group>
	</div>
</template>

<script>
	import { Tab, Tabs, List } from 'vant';
	import TabGroup from "../../components/currency/tab/tab.vue";
	import NormalOrderList from '../../components/currency/order-item/normal-list-platform-manage.vue';

	export default {
		name: 'GeneralROrderListing',
		components: {
			[Tab.name]: Tab, [Tabs.name]: Tabs, [List.name]: List,
			NormalOrderList, TabGroup
		},
		data() {
			return {
				navButtonGroup: [
					{
						name: "暂存点订单", route: { path: '/GeneralRepository/index' }
					},
					{
						name: "待取", route: { path: '/GeneralRepository/waiting-point-map' }
					},
					{
						name: "查询报价", route: { path: '/GeneralRepository/enquiry-quotation' }
					},
					{
						name: "个人中心", route: { path: '/GeneralRepository/personal-center' }
					}
				],
				tabs: {
					index: 0
				},
				collectGR: {
					loading: false,
					finished: false,
					textType: 'collectGR',
					page: 0,
					list_rows: 10,
					dataset: []
				},
				confirmGR: {
					page: 0,
					list_rows: 10,
					loading: false,
					finished: false,
					textType: 'confirmGR',
					dataset: []
				},
				completeGR: {
					page: 0,
					list_rows: 10,
					loading: false,
					finished: false,
					textType: 'completeGR',
					dataset: []
				}
			}
		},
		mounted() {
			this.tabs.index = this.$route.query.index;
			 console.log(this.$store.state.options.user.token)
		},
		methods: {
			getOrderList(items) {
				var that = this;
				var status = '';
				switch (items.textType) {
					case 'collectGR':
						status = 1;
						break;
					case 'confirmGR':
						status = 3;
						break;
					case 'completeGR':
						status = 6;
						break;
				}
				var url = '/api/home/order/getlist';
				var param = {
					page: items.page,
					list_rows: items.list_rows,
					status: status,
					utype: 3,
					token: that.$store.state.options.user.token
				};
				var detail = [];
				this.$util.postRequestInterface(url, param, (res) => {
					items.page = items.page + 1;
					if (res.data == '') {
						items.loading = false;
						items.finished = true;
					} else {
						for (let i of res.data.data) {
							for (let x of i.detail) {
								detail.push({
									title: x.garbagename,
									// number: x.weighting_method == 1 ? x.weighting_num : '',
									// weight: x.weighting_method == 0 ? x.weighting_num : '',
									number: x.weighting_num,
									unit: x.danweiming,
									time: that.$moment(i.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
								})
							}
							items.dataset.push({
								base: {
									id: i.id,
									number: i.ordernumber,
									amount: i.price,
									protect: i.isbaozhi,
									price: i.price,
									name: i.username,
								},
								items: detail
							});
							detail = []
						}
						items.loading = false;
						if (items.dataset.length >= res.data.count) {
							items.finished = true;
						}
					}
				})
			},
			onLoad(textType) {
				switch (textType) {
					case 'collectGR':
						this.getOrderList(this.collectGR);
						break;
					case 'confirmGR':
						this.getOrderList(this.confirmGR);
						break;
					case 'completeGR':
						this.getOrderList(this.completeGR);
						break;
				}
			}
		}
	}
</script>

<style lang = 'scss' scoped>
	.page-top {
		width: 100%;
		height: 3rem;
		position: relative;

		.notice {
			position: absolute;
			top: 0rem;
			width: 100%;
			margin: 0rem;
			padding: 0.7rem 1rem;
			display: flex;
			background: rgba(255, 247, 209, 1);
			z-index: 1;
			box-sizing: border-box;

			dt {
				padding-right: 1rem;

				img {
					width: 1.4rem;
				}
			}

			dd {
				white-space: nowrap;
				flex: 1;
				margin: 0rem;
				padding: 0rem;
				color: #ff9000;
				font-size: 1.3rem;
			}
		}
	}

	.order-list-items {
		.el-item {
			padding: 0.5rem 1rem 0rem;
		}
	}
</style>
